Ref the popover before activating the item
authorGarrett Regier <garrettregier@gmail.com>
Sat, 23 Aug 2014 13:55:07 +0000 (06:55 -0700)
committerGarrett Regier <garrettregier@gmail.com>
Sat, 23 Aug 2014 14:51:59 +0000 (07:51 -0700)
Otherwise the item could cause the popover to be destroyed,
for example a Quit item, and cause a warning to be printed.

gtk/gtkmenusectionbox.c

index 1bc2472c22c90f35aa95f0c0d656546659d7c094..648e93361ab85027edffbea4a75e1b11547dc159 100644 (file)
@@ -145,11 +145,24 @@ gtk_popover_item_activate (GtkWidget *button,
                            gpointer   user_data)
 {
   GtkMenuTrackerItem *item = user_data;
+  GtkWidget *popover = NULL;
+
+  if (gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
+    {
+      /* Activating the item could cause the popover
+       * to be free'd, for example if it is a Quit item
+       */
+      popover = g_object_ref (gtk_widget_get_ancestor (button,
+                                                       GTK_TYPE_POPOVER));
+    }
 
   gtk_menu_tracker_item_activated (item);
 
-  if (gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
-    gtk_widget_hide (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER));
+  if (popover != NULL)
+    {
+      gtk_widget_hide (popover);
+      g_object_unref (popover);
+    }
 }
 
 static void